﻿// --------------------------------------------------------------------------------------------------------------------- 
// <copyright file="ServiceControl.asmx.cs" company="Scrum for Team System">
//   None
// </copyright>
// <summary>
//   Defines the ServiceControl type.
// </summary>
// ---------------------------------------------------------------------------------------------------------------------
namespace ScrumForTeamSystem.EventService.WebService
{
    using System.Web.Services;

    using Properties;

    /// <summary>
    /// Defines the ServiceControl type.
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    public class ServiceControl : WebService 
    {
        /// <summary>
        /// Initializes static members of the <see cref="ServiceControl"/> class.
        /// </summary>
        static ServiceControl()
        {
            IsListening = Settings.Default.EnableWorkItemChangedProcessing;
        }

        /// <summary>
        /// Gets or sets a value indicating whether this instance is listening.
        /// </summary>
        /// <value>
        /// <c>true</c> if this instance is listening; otherwise, <c>false</c>.
        /// </value>
        internal static bool IsListening { get; set; }

        /// <summary>
        /// Starts the service.
        /// </summary>
        /// <returns>Status message.</returns>
        [WebMethod]
        public string Start() 
        {
            IsListening = true;
            return "Service started.";
        }

        /// <summary>
        /// Stops this instance.
        /// </summary>
        /// <returns>Status message.</returns>
        [WebMethod]
        public string Stop()
        {
            IsListening = false;
            return "Service stopped.";
        }

        /// <summary>
        /// Shows the service status.
        /// </summary>
        /// <returns>Status message.</returns>
        [WebMethod]
        public string Status()
        {
            return IsListening ? "Service started." : "Service stopped.";
        }
    }
}
